package com.fizzkai.p2p.core.util;

import com.fizzkai.p2p.core.exception.DisplayableException;

public abstract class AssertUtil {


    /**
     * 断言 两个 对象相等
     * @param obj1
     * @param obj2
     * @param msg
     */
    public static void isEquals(Object obj1, Object obj2, String msg){
        if (!obj1.equals(obj2)) {
            throw new DisplayableException(msg);
        }
    }

    /**
     * 断言 对象 不为空
     * @param str
     * @param msg
     */
    public static void isNotNull(String str, String msg){
        if (str == null || str.length() == 0) {
            throw new DisplayableException(msg);
        }
    }
    /**
     * 断言 对象 不为空
     * @param obj
     * @param msg
     */
    public static void isNotNull(Object obj, String msg) {
        if (obj == null || "".equals(obj)) {
            throw new DisplayableException(msg);
        }
    }
    /**
     * 断言 对象 不为空
     * @param objs
     * @param msg
     */
    public static void allNotNull(String msg, Object ... objs) {
        for (Object obj : objs) {
            if (obj == null || "".equals(obj)) {
                throw new DisplayableException(msg);
            }
        }
    }

    public static void updateNotZero(int num) {
        if (num == 0) {
            throw new DisplayableException("系统繁忙，请稍后再试");
        }
    }
}
